/**
 * 
 */
package com.desksoft.ecommerce.helper;

import javax.servlet.http.HttpServletRequest;

import org.springframework.ui.ModelMap;

import com.desksoft.ecommerce.constants.Constants;
import com.desksoft.ecommerce.helper.mall.SiteinfoHelper;
import com.desksoft.ecommerce.service.interf.logistics.IRegistryService;
import com.desksoft.ecommerce.util.freemarker.FreemarkerStaticUtil;
import com.desksoft.ecommerce.util.holder.ApplicationContextHolder;
import com.desksoft.ecommerce.util.result.ServiceResult;
import com.desksoft.ecommerce.vo.logistics.RegistryQryVO;
import com.desksoft.ecommerce.vo.logistics.RegistryVO;
import com.desksoft.ecommerce.vo.mall.MallSiteInfoVO;
import com.desksoft.utility.request.RequestUtil;
import com.desksoft.utility.resource.PropertiesUtil;
import com.desksoft.utility.resource.ResourceUtil;

/***************************************
 * <pre>
 * 版权所有：杭州迪科软件 保留所有权利
 * 创建日期: Jun 20, 2012
 * 创建作者：yejw
 * 文件名称：ParamterAppendHelper.java
 * 版本：1.0
 * 功能：
 * 最后修改时间：Jun 20, 2012
 * 修改记录：
 * </pre>
 *****************************************/
public class ParamterAppendHelper {

	/**
	 * 追加参数
	 * 
	 * @param request
	 * @param model
	 */
	public static void paramAppend(HttpServletRequest request, ModelMap model) {

		if (!model.containsKey("basePath")) {
			model.put("basePath", ResourceUtil.getServiceResource().getProperty("remote.common.server.address"));
			//model.put("basePath", RequestUtil.getAppURL(request));
		}

		if (!model.containsKey("contextPath")) {
			model.put("contextPath", request.getContextPath() + "/");
		}

		if (!model.containsKey("sessionId")) {
			model.put("sessionId", request.getSession().getId());
		}

		if (!model.containsKey("static")) {
			model.put("static", Constants.STATIC_SERVICE);
		}

		if (!model.containsKey("logistics")) {
			model.put("logistics", String.format("%s/%s", Constants.STATIC_SERVICE, "logistics"));
		}

		String theme = PropertiesUtil.getProperty("mall.site.static.base.theme", "default");

		if (!model.containsKey("mallTheme")) {
			model.put("mallTheme", theme);
		}

		if (!model.containsKey("mall")) {
			model.put("mall", String.format("%s/%s/%s", Constants.STATIC_SERVICE, "proj/mall", theme));
		}

		if (!model.containsKey("saleAssistant")) {
			model.put("saleAssistant", String.format("%s/%s", Constants.STATIC_SERVICE, "saleAssistant"));
		}

		if (!model.containsKey("tmsInter")) {
			model.put("tmsInter", String.format("%s/%s", Constants.STATIC_SERVICE, "tmsInter"));
		}

		if (!model.containsKey("vendor")) {
			model.put("vendor", String.format("%s/%s", Constants.STATIC_SERVICE, "vendor"));
		}

		if (!model.containsKey("image")) {
			model.put("image", ResourceUtil.getServiceResource().getProperty("remote.image.address"));
		}

		if (!model.containsKey("mallServ")) {
			model.put("mallServ", ResourceUtil.getServiceResource().getProperty("remote.mall.server.address"));
		}
		if (!model.containsKey("managerServ")) {
			model.put("managerServ",
					ResourceUtil.getServiceResource().getProperty("remote.manager.pages.server.address"));
		}

		if (!model.containsKey("mallPageServ")) {
			model.put("mallPageServ", ResourceUtil.getServiceResource().getProperty("remote.mall.pages.server.address"));
		}
		if (!model.containsKey("vendorServ")) {
			model.put("vendorServ", ResourceUtil.getServiceResource().getProperty("remote.vendor.serviceurl.address"));
		}

		if (!model.containsKey("sdefaultimg")) {
			model.put("sdefaultimg", model.get("image") + Constants.sdefaultimg);
		}
		if (!model.containsKey("ddefaultimg")) {
			model.put("ddefaultimg", model.get("image") + Constants.ddefaultimg);
		}
		if (!model.containsKey("tdefaultimg")) {
			model.put("tdefaultimg", model.get("image") + Constants.tdefaultimg);
		}

		if (!model.containsKey("defaultimg")) {
			model.put("defaultimg", model.get("image") + Constants.defaultimg);
		}
		if (!model.containsKey("vendorShopTag")) {
			model.put("vendorShopTag", ResourceUtil.getServiceResource().getProperty("remote.vendor.server.address"));
		}
		
		// 是否有站点信息
//		MallSiteInfoVO vo = SiteinfoHelper.getInstance();
//
//		if (null != vo) {
//			if (!model.containsKey("vendorShopTag")) {
//				
//				IRegistryService registryService = (IRegistryService) ApplicationContextHolder.get("registryService");
//				RegistryQryVO registryQryVO = new RegistryQryVO();
//				registryQryVO.setUserId(SiteinfoHelper.getInstance().getUserid());
//				registryQryVO.setValueName("syncServiceVendorShopTag");
//				registryQryVO.setRegKey("Vendor");
//				ServiceResult<RegistryVO> vendorSettingResult = registryService.getRegistryByKeyAndVals(registryQryVO);
//				if (vendorSettingResult.isSuccess()) {
//					if(vendorSettingResult.getResult() !=null){
//						model.put("vendorShopTag", vendorSettingResult.getResult().getValue());
//					}
//				}
//				if (model.get("vendorShopTag") == null) {
//					model.put("vendorShopTag", Constants.VENDOR_SHOPTAG);
//				}
//			}
//		}
		FreemarkerStaticUtil.setDefaultStaticModel(model);

	}
}
